package cn.kgc.myhousemputils;


import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class GetCode {
    public static void main(String[] args) {
        /*代码生成器*/
        AutoGenerator mpg = new AutoGenerator();
        /*获取路径*/
        String projectPath = System.getProperty("user.dir");
        System.out.println("projectPath:"+projectPath);
        /*全局配置*/
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setOutputDir(projectPath + "\\myhouse-mp-utils\\src\\main\\java");
        globalConfig.setAuthor("liguopeng");
        globalConfig.setOpen(false);
        mpg.setGlobalConfig(globalConfig);
        /*配置数据源*/
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setUrl("jdbc:mysql://122.10.18.105:3306/myhouse?useUnicode=true&useSSL=false&characterEncoding=utf8");
        dataSourceConfig.setDriverName("com.mysql.jdbc.Driver");
        dataSourceConfig.setUsername("myhouse");
        dataSourceConfig.setPassword("123456");
        mpg.setDataSource(dataSourceConfig);
        /*配置包*/
        PackageConfig pc=new PackageConfig();
        //String packpre="cn.kgc.myhousemputils.";
        pc.setParent("cn.kgc.myhousemputils");
        pc.setEntity("bean");
        pc.setController("controller");
        pc.setMapper("mapper");
        pc.setXml("classpath:mapper");
        pc.setService("service");
        pc.setServiceImpl("serviceImpl");
        mpg.setPackageInfo(pc);
        /*自定义配置*/
        InjectionConfig injectionConfig=new InjectionConfig() {
            @Override
            public void initMap() {

            }
        };
        mpg.setCfg(injectionConfig);
        /*策略配置*/
        StrategyConfig strategyConfig=new StrategyConfig();
        strategyConfig.setNaming(NamingStrategy.underline_to_camel);//下划线字段转换
        strategyConfig.setColumnNaming(NamingStrategy.underline_to_camel);//下划线字段转换
        strategyConfig.setRestControllerStyle(true);//Controller自动Rest风格生成
        strategyConfig.setInclude("liver","house","liverorder","houseorder","wxfk","houseregist","room","system","manage");//表名
        mpg.setStrategy(strategyConfig);
        // 配置模板
        TemplateConfig templateConfig = new TemplateConfig();

        // 配置自定义输出模板
        //指定自定义模板路径，注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别
        // templateConfig.setEntity("templates/entity2.java");
        // templateConfig.setService();
        // templateConfig.setController();

        templateConfig.setXml(null);
        mpg.setTemplate(templateConfig);

        mpg.execute();





    }
}
